import 'package:flutter/material.dart';
import 'package:flutter_app_05/page/calpage/pagecal07.dart';
import 'package:flutter_app_05/utils/MyTheme.dart';
import 'package:flutter_app_05/utils/ScreenAdapter.dart';

import 'calculator.dart';
import 'calpage/page01.dart';
import 'calpage/pagecal01.dart';
import 'calpage/pagecal02.dart';
import 'calpage/pagecal03.dart';
import 'calpage/pagecal04.dart';
import 'calpage/pagecal05.dart';
import 'package:flutter_app_05/widget/sdk_extens.dart';

class _TabData {
  final Widget tab;
  final Widget body;

  _TabData({this.tab, this.body});
}

final _tabDataList = <_TabData>[
  _TabData(tab: Text('管径计算'), body: Padecalone()),
  _TabData(tab: Text('阻力计算'), body: Padecalthree()),
  _TabData(tab: Text('水泵计算'), body: Padecalseven()),
  _TabData(tab: Text('膨胀系数'), body: Padecalfour()),
  _TabData(tab: Text('换热器计算'), body: Padecalfive())
];

class FirstPage extends StatefulWidget {
  int pagenum = 0;

  FirstPage({this.pagenum});

  @override
  _FirstPageState createState() => _FirstPageState();
}

class _FirstPageState extends State<FirstPage> {
  final tabBarList = _tabDataList.map((item) => item.tab).toList();
  final tabBarViewList = _tabDataList.map((item) => item.body).toList();

  @override
  Widget build(BuildContext context) {
    print(widget.pagenum.toString());
    ScreenAdapter.init(context);
    return Scaffold(
      resizeToAvoidBottomInset: false,
      appBar: AppBar(
        centerTitle: true,
        backgroundColor: MyTheme(context).getColor("tab_bg"),
        shadowColor: Colors.transparent,
        brightness: MyTheme(context).getCurrentTheme()==1?Brightness.light:Brightness.dark,
        leading: IconButton(
            color: MyTheme(context).getColor('colorBlack'),
            icon: Icon(Icons.arrow_back_ios),
            onPressed: () {
              Navigator.pop(context);
            }),
      ),
      body: DefaultTabController(
          length: tabBarList.length,
          initialIndex: widget.pagenum,
          child: Column(
            children: <Widget>[
              Container(
                width: double.infinity,
                height: 50,
                alignment: Alignment.centerLeft,
                color: MyTheme(context).getColor("tab_bg"),
                child: TabBar(
                    indicator: const BoxDecoration(),
                    isScrollable: true,
                    indicatorColor: MyTheme.colorLight['app_green'],
                    indicatorSize: TabBarIndicatorSize.label,
                    unselectedLabelColor:
                        MyTheme(context).getColor("text_unselect"),
                    unselectedLabelStyle: TextStyle(fontSize: 15),
                    labelColor: MyTheme(context).getColor("text_select"),
                    labelStyle: TextStyle(fontSize: 20),
                    tabs: tabBarList),
              ),
              Expanded(
                  child: TabBarView(
                children: tabBarViewList,
                // physics: NeverScrollableScrollPhysics(), // 禁止滑动
              ))
            ],
          )),
    );
  }
}
